package com.lin.gram.controller.graphController;

import com.lin.gram.pojo.graphPojo.*;
import com.lin.gram.service.graphService.PatentService;
import com.lin.gram.pojo.graphPojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author ChenweiLin
 * @create 2021-05-03 16:18
 */
@RestController
@RequestMapping("/api/patent")
public class PatentController {
    @Autowired
    PatentService patentService;

    /**
     * 单个节点信息的获取
     * @param patent
     * @return 单个专利节点
     */
    @PostMapping("/find")
    public CustomNode findByApplicationNum(@RequestBody Patent patent){
        String applicationNum = patent.getApplicationNum();
        System.out.println(applicationNum);
        Patent pa = patentService.findByApplicationNum(applicationNum);
//        System.out.println(pa.toString());

        return new CustomNode(pa.getName(), 1, pa);
    }

    /**
     * 获取 patent belongto applicant 的applicant集合及节点信息
     * @param querySizer
     * @return applicantSet
     */
    @PostMapping("/belongto")
    public List<CustomNode> getBelongto(@RequestBody QuerySizer querySizer){
        System.out.println(querySizer.toString());
        List<CustomNode> customNodes = new ArrayList<>();
        String currentNodeNum = querySizer.getCurrentNodeNum();
        Patent pa = patentService.findByApplicationNum(currentNodeNum);
        Set<Applicant> applicantSet = pa.getBelongToApplicant();

        for (Applicant applicant : applicantSet) {
            customNodes.add(new CustomNode(applicant.getName(), 2,applicant));
        }

        return customNodes;
    }

    /**
     * 
     * @param querySizer
     * @return
     */
    @PostMapping("/becreatedby")
    public List<CustomNode> getBeCreatedBy(@RequestBody QuerySizer querySizer){
        System.out.println(querySizer.toString());
        List<CustomNode> customNodes = new ArrayList<>();
        String currentNodeNum = querySizer.getCurrentNodeNum();
        Patent pa = patentService.findByApplicationNum(currentNodeNum);
        Set<Inventor> inventorSet = pa.getBeCreatedByInventor();
        for (Inventor inventor : inventorSet) {
            customNodes.add(new CustomNode(inventor.getName(),4, inventor));
        }
        return customNodes;
    }


    @PostMapping("/query")
    public List<CustomNode> findNodeByRel(@RequestBody QuerySizer querySizer){
        System.out.println(querySizer.toString());
        String currentNodeNum = querySizer.getCurrentNodeNum();
        Patent patent = patentService.findByApplicationNum(currentNodeNum);
        String rel = querySizer.getCurrentType();


        return  null;
    }
}
